#ifndef XX_COMMON_TCPSESSION_HH
#define XX_COMMON_TCPSESSION_HH
#include "httpParser.h"
#include "osip_mt.h"
#include <thread>
#include "JSONParse.h"
#include "ThreadPool.h"
#include "common.h"
#include "Buffer.h"
#include <functional>

#define NETCMD_BASE							0x10000
#define NETCMD_FLAG							0x4E494F4E
#define NET_VERSION							0x1001001

#define NETCMD_EXECSQLFUNC			    (NETCMD_BASE + 0x100)  //增删改
#define NETCMD_RAWQUERYFUNC		        (NETCMD_BASE + 0x101)  //查询

typedef struct tagCOMMNET_HEADER
{
public:
	tagCOMMNET_HEADER() {
		nFlag = 0;
		dwCmd = 0;
		dwvsion = 0;
		dwBufSize = 0;
	}

	unsigned int	nFlag;
	unsigned int	dwCmd;
	unsigned int	dwvsion;
	unsigned int	dwBufSize;
}COMMNET_HEADER;

class CTCPSession : public zl::Task
{
public:
	CTCPSession();
	// virtual void Run();
	virtual int run();
	virtual ~CTCPSession();
	virtual int StopServer();
	virtual int StartServer(const socket_t fdClient);
	virtual void OnReceive(const char* data, int len);
	virtual int sendMessage(const char* data, int len);
	void sendJson(int cmd, cJSON* json);

private:
	char* m_chars;
	unsigned int 				m_lengh;
	socket_t					m_fdClient;
	std::atomic<bool> 			m_quit;
};
#endif
